<?php
/**
 * Ressource Header
 * Add a new ressource : Header Block
 *
 * @author Xavier VILAIN
 * @package ressource
 */

use Fox\Authorization;
use Hive\Education\Level;
use Fox\Html\Block;
use Fox\Behaviors;
use Fox\Html\Html;
use Fox\Dao\SqlFragment;
use Hive\Ressource\Source;
use Fox\Html\Wrapper;
use Fox\Html\Input;
use Fox\Generator;
use Hive\Ressource;
use Fox\Html\DropList;

$xview = Xview::instance();
$grouping = User::current()->group();

$wrapper = new Wrapper('wPersonnal');

$block = new Fox\Html\Block('bPersonnal',Msg(Hive::BUNDLE,Hive::LABEL_PERSONNAL_DATA));

if(Hive\Customizing::instance()->hasGroup()) {
	$finder = new Ressource\Group();
	$block->add(new DropList(array('contact_group','grouping'),false,false,false,$grouping))
			->options($finder->find(),'grouping','name');
	if(!Fox\Authorization\Manager::check(Hive\Ressource::AUTH_GROUP_CAN_CHG)) {
		$block->item('grouping')->input(false);
	}
}

$block->add(new DropList(array('res_status','status'),false,false,false,Ressource::STATUS_WIP),2)
		->options(Hive\Contact\Status::loadActives(),'status',Fox\Generator::call('label'));
if(!Fox\Authorization\Manager::check(Hive\Ressource::AUTH_STATUS_CAN_VALID)) {
	$block->item('status')->input(false);
}

$block->add(new Input('first_name',true))->size(25);
$block->add(new Input('email',true),2,'first_name')
		->label(' 1',false,Input::LABEL_ADD_AFTER)
		->size(25);
$block->add(new Input(array('email1','email1'),false),2)
		->label(' 2',false,Input::LABEL_ADD_AFTER)
		->size(25);
$block->add(new Input('last_name',true))->size(25);
$block->add(new Input('birth_date',false),2)
			->yearRange('1965:2010');
$block->add(new DropList('gender',true));
$block->add(new Input(array('adress','street'),false))->size(Input::SIZE_XLARGE);
$block->add(new Input('postal_code',false));
$block->add(new Input('city',false))->size(25);
$block->add(new DropList('country',true,true,false))
		->loadFromSession()
		->saveInSession();
$block->add(new Input(array('phone','phone1'),false),2)
		->label(' 1',false,Input::LABEL_ADD_AFTER)
		->size(25);
$block->add(new Input(array('phone','phone2'),false),2)
		->label(' 2',false,Input::LABEL_ADD_AFTER)
		->size(25);
		
// Diploma ?
$levels = Hive\Education\Level::loadActives();
$block->add(new DropList('scholar',true),2)
		->options($levels,'level',Generator::call('label'))
		->source(Generator::url('education','levels','droplist'));
		
if(Authorization\Manager::check(Hive\Authorizations::EDUCATION_LEVEL_W)) {
$block->item('scholar')->add(new \Fox\Html\Action\Anchor('addLevel',
			Behaviors::action(Generator::url('education','levels','modify',array('area' => 'contact-create')),true)
			))->label('<span class="action-links" title="'.Msg(Hive::BUNDLE,Hive::ADD_NEW_LEVEL).'">[+]</span>');
}
$block->add(new Input('school',false),2)->size(Input::SIZE_XLARGE)
			->autocomplete(Generator::url('education','autocomplete'));
$block->add(new Input('kn_number_year',false),2)
		->label(Msg(Hive::BUNDLE,Hive::NB_OF_YEARS_OF_EXP))
		->add(new Input(array('cdate','kn_udate')))
		->displayMode(Input::DISPLAY_READONLY)
		->noLabel();
		
$wrapper->add($block);
		
// Source of the profile
$blSource = new Block('blSource',Msg(Hive::BUNDLE,Hive::CONTACT_SOURCE));
$blSource->add(new DropList(array('contact_source','source'),true))
		->options(Hive\Contact\Source::loadActives(),'source',Generator::call('label'))
		->source(Generator::url('contacts','sources','droplist'));
		
if(Authorization\Manager::check(Hive\Authorizations::CONTACT_SOURCES_W)) {
$blSource->item('source')->add(new \Fox\Html\Action\Anchor('addSource',
			Behaviors::action(Generator::url('contacts','sources','modify',array('area' => 'contact-create')),true)
			))->label('<span class="action-links hastooltip" title="'.Msg(Hive::BUNDLE,Hive::ADD_A_SOURCE).'">[+]</span>');
}
$wrapper->add($blSource);

// Social Links
$sources = Fox\Dao::finder(Source\Type::className())
				->where('active = ?',array(true))
				->find();			
foreach($sources as $source) {
	if($source->followed > 0) {
		$followedSources[] = $source;
	}
}

if(isset($followedSources)) {
	$blSoc = new Fox\Html\Block('bSocial',Msg(Hive::BUNDLE,Hive::LABEL_SOCIAL_NETWORKS));
	foreach($followedSources as $type ){
		
		$blSoc->add(new Input(array('social_reference','social_'.$type->type)))
					->size(Input::SIZE_XXLARGE)
					->label($type->label);
	
	}
}
$wrapper->add($blSoc);
return $wrapper;